import 'package:backend.core/core/domain/entities/web/yookassa/yookassa_payment_method.dart';
import 'package:backend.core/core/domain/utils/uuid_generator.dart';
import 'package:backend.purchases/domain/entities/yookassa_api/payments/yookassa_api_succeeded_payment_method.dart';
import 'package:backend.purchases/domain/helpers/yookassa/create_yookassa_bank_card_info_from_api_one.dart';

abstract class CreateYookassaPaymentMethodFromApiOne {
  YookassaPaymentMethod call({
    required YookassaApiSucceededPaymentMethod apiPaymentMethod,
    required String userId,
  });
}

class CreateYookassaPaymentMethodFromApiOneImpl implements CreateYookassaPaymentMethodFromApiOne {
  const CreateYookassaPaymentMethodFromApiOneImpl({
    required CreateYookassaBankCardInfoFromApiOne createYookassaBankCardInfoFromApiOne,
  }) : _createYookassaBankCardInfoFromApiOne = createYookassaBankCardInfoFromApiOne;

  final CreateYookassaBankCardInfoFromApiOne _createYookassaBankCardInfoFromApiOne;

  @override
  YookassaPaymentMethod call({
    required YookassaApiSucceededPaymentMethod apiPaymentMethod,
    required String userId,
  }) {
    final id = UuidGenerator().generateUuid();

    final bankCardInfo = _createYookassaBankCardInfoFromApiOne(
      apiBankCardInfo: apiPaymentMethod.bankCardInfo,
    );

    return YookassaPaymentMethod(
      id: id,
      userId: userId,
      saved: apiPaymentMethod.saved,
      test: apiPaymentMethod.test,
      yookassaApiPaymentMethodId: apiPaymentMethod.id,
      bankCardInfo: bankCardInfo,
      failure: null,
    );
  }
}
